package com.celesea.auth.group.v1.controller;

import com.celesea.auth.group.entity.Group;
import com.celesea.auth.group.service.GroupService;
import com.celesea.auth.group.v1.controller.resource.GroupResource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author JackYuan
 * @create 2017-10-26 23:30
 */
@Api(tags = "群组接口")
@RestController
@RequestMapping("v1/api/groups")
public class GroupApiController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private GroupService groupService;

    @GetMapping()
    @ApiOperation(value = "群组列表")
    public List<GroupResource> list() {
        List<Group> list = groupService.selectGroups();
        return list.stream()
                .map(item -> new GroupResource(item))
                .collect(Collectors.toList());
    }

}
